package com.autumn.demo.cfg;

import java.util.HashMap;
import java.util.Map;

import com.autumn.runtime.session.TestAutumnSession;
import com.autumn.runtime.session.claims.IdentityClaims;

/**
 * 测试会话
 * 
 * @author 老码农
 *
 *         2017-12-01 13:01:19
 */
public class UserTestSessionImpl extends TestAutumnSession {

	private final static Map<String, Object> TEST_IDENTITYCLAIMS = new HashMap<>();

	static {
		TEST_IDENTITYCLAIMS.put(IdentityClaims.CLAIMS_DATA_SOURCE_IDENTITY, "shop1");
	}

	public UserTestSessionImpl() {
		this.setUserId(1L);
		this.setUserName("测试员");
		this.setIdentityClaimsMap(TEST_IDENTITYCLAIMS);
	}

	public UserTestSessionImpl(long userId, String userName) {
		super(userId, userName);
		this.setIdentityClaimsMap(TEST_IDENTITYCLAIMS);
	}

	private int count = 0;

	@Override
	public IdentityClaims getIdentityClaims() {
		if (count % 2 == 0) {
			TEST_IDENTITYCLAIMS.put(IdentityClaims.CLAIMS_DATA_SOURCE_IDENTITY, "shop2");
		} else {
			TEST_IDENTITYCLAIMS.put(IdentityClaims.CLAIMS_DATA_SOURCE_IDENTITY, "shop1");
		}
		count++;
		this.setIdentityClaimsMap(TEST_IDENTITYCLAIMS);
		return super.getIdentityClaims();
	}

}
